package com.cn.topAndFoot.service.impl;

import com.cn.common.pojo.CompanyModel;
import com.cn.common.pojo.ResultModel;
import com.cn.topAndFoot.mapper.CompanyDao;
import com.cn.topAndFoot.service.CompanyService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    CompanyDao companyDao;
    @Override
    public ResultModel getCompany() {
        return ResultModel.Data(companyDao.getCompany());
    }

    @Override
    public ResultModel delete(int id) {
        int delete = companyDao.delete(id);
        return ResultModel.getResultModelByCount(delete);
    }

    @Override
    public ResultModel update(CompanyModel companyModel) {
        int update = companyDao.update(companyModel);
        return ResultModel.getResultModelByCount(update);
    }

    @Override
    public ResultModel insert(CompanyModel companyModel) {
        int insert = companyDao.insert(companyModel);
        return ResultModel.getResultModelByCount(insert);
    }

    @Override
    public ResultModel enable(int id) {
        int enable = companyDao.enable(id);
        return ResultModel.getResultModelByCount(enable);
    }

    @Override
    public ResultModel findById(int id) {

        return ResultModel.getResultModelByAll(companyDao.findById(id),1);
    }

    @Override
    public ResultModel findAll(int limit,int page) {
        PageHelper.startPage(limit,page);
        List<CompanyModel> all = companyDao.findAll();
        PageInfo<CompanyModel> companyModelPageInfo = new PageInfo<>(all);
        return ResultModel.getResultModel("",0,(int) companyModelPageInfo.getTotal(),companyModelPageInfo.getList());
    }
}
